home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 10878 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.1 KB

  1. Path: falcon.ukc.ac.uk!bj2
  2. From: bj2@ukc.ac.uk (B.Jury)
  3. Newsgroups: comp.lang.c++
  4. Subject: Random File Access (fstream)
  5. Date: Mon, 11 Mar 96 16:22:45 GMT
  6. Organization: University of Kent at Canterbury, UK.
  7. Message-ID: <12708@falcon.ukc.ac.uk>
  8. NNTP-Posting-Host: falcon.ukc.ac.uk
  9.  
  10. Can anyoe please tell me why the following program does not work at all??
  11.  
  12. int test(int pos) {
  13.     datastruct    temp;
  14.  
  15.     ofstream output("File.Bin",ios::ate);
  16.     if (!output) { return 1; }
  17.  
  18.     output.seekp(pos*sizeof(temp));
  19.  
  20.      output.write((char *)&temp,sizeof(temp));
  21.     
  22.     output.close();
  23.     return 0;
  24. }
  25.  
  26. tellp() reports the pointer is at the coprrect place, and eof() also
  27. is OK, so why doesnt output.write write to the file?!? Ive hunted
  28. on the WWW, cant find any example code, so any help would be apreciated.
  29.  
  30. Regards,
  31. -Ben.
  32. --
  33. \ \\    B.Jury - University Of Kent. PAL PSeX Owner. Wanna trade games?    // /
  34.  \ \\ Frontier - First Encounters Black Space Patch available on request. // /
  35.   \ \\    Opinions are my own, and maybe yours, if not i dont care :)    // /  
  36. \  \ \\  * Dammit, keep posts to 75 chars wide, for us poor unixers. *  // /  /
  37.